package xy.come.guidelibrary;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import xy.come.guidelibrary.listeners.PaperOnBoardingOnChangeListener;
import xy.come.guidelibrary.listeners.PaperOnBoardingOnLeftOutListener;
import xy.come.guidelibrary.listeners.PaperOnBoardingOnRightOutListener;

/**
 * Created by Xia_焱 on 2018/7/11.
 * e-mail：XiahaotianV@163.com
 */

public class PaperOnBoardingFragment extends Fragment {

    private static final String ELEMENTS_PARAM = "elements";

    private PaperOnBoardingOnChangeListener mOnChangeListener;
    private PaperOnBoardingOnRightOutListener mOnRightOutListener;
    private PaperOnBoardingOnLeftOutListener mOnLeftOutListener;
    private ArrayList<PaperOnBoardingPage> mElements;


    public static PaperOnBoardingFragment newInstance(ArrayList<PaperOnBoardingPage> elements) {
        PaperOnBoardingFragment fragment = new PaperOnBoardingFragment();
        Bundle args = new Bundle();
        args.putSerializable(ELEMENTS_PARAM, elements);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mElements = (ArrayList<PaperOnBoardingPage>) getArguments().get(ELEMENTS_PARAM);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.onboarding_main_layout, container, false);

        // create engine for onboarding element
        PaperBoardingEngine mPaperOnBoardingEngine = new PaperBoardingEngine(view.findViewById(R.id.onboardingRootView), mElements, getActivity().getApplicationContext());
        // set listeners
        mPaperOnBoardingEngine.setOnChangeListener(mOnChangeListener);
        mPaperOnBoardingEngine.setOnLeftOutListener(mOnLeftOutListener);
        mPaperOnBoardingEngine.setOnRightOutListener(mOnRightOutListener);

        return view;
    }

    public void setElements(ArrayList<PaperOnBoardingPage> elements) {
        this.mElements = elements;
    }

    public ArrayList<PaperOnBoardingPage> getElements() {
        return mElements;
    }

    public void setOnChangeListener(PaperOnBoardingOnChangeListener onChangeListener) {
        this.mOnChangeListener = onChangeListener;
    }

    public void setOnRightOutListener(PaperOnBoardingOnRightOutListener onRightOutListener) {
        this.mOnRightOutListener = onRightOutListener;
    }

    public void setOnLeftOutListener(PaperOnBoardingOnLeftOutListener onLeftOutListener) {
        this.mOnLeftOutListener = onLeftOutListener;
    }

}
